
/**
 * @file:       index.hpp
 * @author:     WubinWang
 * @contact:    wubinstu@163.com
 * @date:       2025-01-01
 * @license:    MIT License
 *
 * Copyright (c) 2025 WubinWang
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * DISCLAIMER:
 * 1. User acknowledges all application risks and consequences arising from usage
 *    of this software are exclusively borne by the user.
 * 2. The original author shall not be held liable for any direct, indirect,
 *    incidental, special, exemplary or consequential damages.
 * 3. No warranty of fitness for particular purpose or non-infringement is provided. */


#ifndef __INDEX_HPP_
#define __INDEX_HPP_

#include <atomic>
#include <cstdint>


#define USE_ATOMIC 1

class Advanced_Circular_Stepper_ct {

  public:
    explicit Advanced_Circular_Stepper_ct (const Advanced_Circular_Stepper_ct & _other) noexcept;
    explicit Advanced_Circular_Stepper_ct (Advanced_Circular_Stepper_ct && _other) noexcept;
    Advanced_Circular_Stepper_ct & operator= (const Advanced_Circular_Stepper_ct & _other) noexcept;
    Advanced_Circular_Stepper_ct & operator= (Advanced_Circular_Stepper_ct && _other) noexcept;

    explicit Advanced_Circular_Stepper_ct (std::int64_t _floor = 0, std::int64_t _ceiling = 100, std::int64_t _interval = 1) noexcept;
    ~Advanced_Circular_Stepper_ct () noexcept;

    operator std::int64_t () const noexcept;
    operator std::int32_t () const noexcept;
    operator std::int16_t () const noexcept;
    operator std::int8_t () const noexcept;

    auto operator= (std::int64_t _index) noexcept -> std::int64_t;
    auto operator= (std::int32_t _index) noexcept -> std::int32_t;
    auto operator= (std::int16_t _index) noexcept -> std::int16_t;
    auto operator= (std::int8_t _index) noexcept -> std::int8_t;

    auto operator+ (std::int64_t _increment) noexcept -> std::int64_t;
    auto operator+ (std::int32_t _increment) noexcept -> std::int32_t;
    auto operator+ (std::int16_t _increment) noexcept -> std::int16_t;
    auto operator+ (std::int8_t _increment) noexcept -> std::int8_t;

    auto operator- (std::int64_t _decrement) noexcept -> std::int64_t;
    auto operator- (std::int32_t _decrement) noexcept -> std::int32_t;
    auto operator- (std::int16_t _decrement) noexcept -> std::int16_t;
    auto operator- (std::int8_t _decrement) noexcept -> std::int8_t;

    auto operator++ () noexcept -> std::int64_t;
    auto operator-- () noexcept -> std::int64_t;
    auto operator++ (int) noexcept -> std::int64_t;
    auto operator-- (int) noexcept -> std::int64_t;

    auto operator+= (std::int64_t _increment) noexcept -> Advanced_Circular_Stepper_ct &;
    auto operator+= (std::int32_t _increment) noexcept -> Advanced_Circular_Stepper_ct &;
    auto operator+= (std::int16_t _increment) noexcept -> Advanced_Circular_Stepper_ct &;
    auto operator+= (std::int8_t _increment) noexcept -> Advanced_Circular_Stepper_ct &;

    auto operator-= (std::int64_t _decrement) noexcept -> Advanced_Circular_Stepper_ct &;
    auto operator-= (std::int32_t _decrement) noexcept -> Advanced_Circular_Stepper_ct &;
    auto operator-= (std::int16_t _decrement) noexcept -> Advanced_Circular_Stepper_ct &;
    auto operator-= (std::int8_t _decrement) noexcept -> Advanced_Circular_Stepper_ct &;

    auto operator== (const Advanced_Circular_Stepper_ct & _other) noexcept -> bool;
    auto operator!= (const Advanced_Circular_Stepper_ct & _other) noexcept -> bool;

    auto operator== (std::int64_t _other) noexcept -> bool;
    auto operator!= (std::int64_t _other) noexcept -> bool;


    auto inc () noexcept -> std::int64_t;
    auto dec () noexcept -> std::int64_t;
    auto add (std::int64_t _increment) noexcept -> std::int64_t;
    auto sub (std::int64_t _decrement) noexcept -> std::int64_t;


    auto getFloor () const noexcept -> std::int64_t;
    auto setFloor (std::int64_t _floor) noexcept -> bool;

    auto getCeiling () const noexcept -> std::int64_t;
    auto setCeiling (std::int64_t _ceiling) noexcept -> bool;

    auto getInterval () const noexcept -> std::int64_t;
    auto setInterval (std::int64_t _interval) noexcept -> bool;

    auto getIndex () const noexcept -> std::int64_t;


  private:

#if defined(USE_ATOMIC) && (USE_ATOMIC == 1)
    std::atomic<std::int64_t> _m_index_floor      = 0;
    std::atomic<std::int64_t> _m_index_ceiling    = 100;
    std::atomic<std::int64_t> _m_stepper_interval = 1;
    std::atomic<std::int64_t> _m_index_location   = 0;
#else
    std::int64_t _m_index_floor      = 0;
    std::int64_t _m_index_ceiling    = 100;
    std::int64_t _m_stepper_interval = 1;
    std::int64_t _m_index_location   = 0;
#endif
};


#endif
